package kr.listAction;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import kr.dao.CouponDao;
import kr.domain.Coupon;
import kr.util.FileUtil;
import kr.controller.Action;

public class DeleteListProAction implements Action{

	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		HttpSession session = request.getSession();
		if(!session.getAttribute("memId").equals("admin")){
			return "/view/loginForm.jsp";
		}
		
		int num = Integer.parseInt(request.getParameter("num"));
		
		CouponDao dao = CouponDao.getInstance();
		Coupon coupon = dao.getCoupon(num);
		
		if(dao.getLog(num)){
			request.setAttribute("type", 1);
			return "/admin/deleteListPro.jsp";
		}
		
		dao.deleteCoupon(num);
		request.setAttribute("num", num);

		request.setAttribute("type", 0);
		return "/admin/deleteListPro.jsp";
	}
}
